package hsp.admin.util;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import hsp.admin.app.base.po.UserPO;
import hsp.admin.app.base.service.IUserService;
import hsp.admin.interceptor.UserIdInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@Component
public class SessionUtil {

    private final IUserService userService;

    @Lazy
    @Autowired
    public SessionUtil(
        IUserService userService
    ) {
        this.userService = userService;
    }

    public long getUserId(){
        return UserIdInterceptor.getUserId();
    }

    public String getUsername(){
        return getUserPO().getUsername();
    }

    public UserPO getUserPO(){
        LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserPO::getId, getUserId());
        return userService.getOne(wrapper);
    }

}
